package co.gov.mintic.Biblioteca.activitys;

import java.util.List;

import co.gov.mintic.Biblioteca.beans.Registro;
import co.gov.mintic.Biblioteca.android.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * Custom adapter with "View Holder Pattern".
 * 
 */
public class CustomArrayAdapter extends ArrayAdapter<Registro> {

	public CustomArrayAdapter(Context context, int textViewResourceId,
			List<Registro> objects) {
		super(context, textViewResourceId, objects);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// holder pattern
		Holder holder = null;
		if (convertView == null) {
			holder = new Holder();

			LayoutInflater layoutInflater = (LayoutInflater) getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = layoutInflater.inflate(R.layout.resultados, null);
			holder.setTextView1((TextView) convertView
					.findViewById(R.id.textView1));
			holder.setTextView2((TextView) convertView
					.findViewById(R.id.textView2));
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}

		String titulo = getItem(position).getTitulo() != null ? getItem(
				position).getTitulo() : "";
		String tema = getItem(position).getTema() != null ? getItem(position)
				.getTema() : "";

		holder.getTextView1().setText((CharSequence) titulo);
		holder.getTextView2().setText((CharSequence) tema);

		return convertView;
	}

}
